<!-- 兑换 -->
<template>
	<view class="draw-money-wrap">
		<view class="head-box">
			<u-navbar
				backIconColor="#fff"
				:borderBottom="false"
				:background="{ background: 'none' }"
				:backTextStyle="{ color: '#fff', fontSize: '32rpx' }"
				backText="兑换金豆"
				:isFixed="false"
			></u-navbar>
			<!-- 可提现 -->
			<view class="wallet-num-box u-flex u-col-center u-row-between">
				<view class="">
					<view class="num-title">可兑换金额（元）</view>
					<view class="wallet-num">{{ userinfo.quanyi || '0.00' }}</view>
				</view>
				<button class="u-reset-button log-btn" @tap="$Router.push({ path: '/pages/user/wallet/quanyi-balance' })">兑换记录</button>
			</view>
		</view>
		<!-- 提现输入卡片-->
		<view class="draw-card">
			<view class="card-title">兑换金额</view>
			<view class="input-box u-flex u-col-center">
				<view calss="unit">￥</view>
				<input class="u-flex-1 u-p-l-10" type="number" @input="onWithdrawInput" v-model="money" :placeholder-style="placeholderStyle" placeholder="请输入兑换金额" />
			</view>
			

			<button class="u-reset-button save-btn" @tap="exchange">确认兑换</button>
		</view>
		<!-- 提现说明 -->
		<view class="draw-notice">
			<view class="title">兑换说明</view>
			<view class="draw-list">1.消费补贴 : 金豆 = 1 : {{ruleInfo.quanyi_to_jindou}}</view>
			<view class="draw-list">2.如有疑问请及时联系客服。</view>
		</view>
		<!-- 提现方式 -->
		

	
		<!-- modal -->
		<u-modal
			ref="uModal"
			v-model="showModal"
			:show-cancel-button="true"
			confirm-color="#7063D2"
			cancel-color="#666666"
			@confirm="$Router.push('/pages/user/wallet/quanyi-balance')"
			confirm-text="查看记录"
			cancel-text="继续兑换"
			content="恭喜您的兑换已完成!"
			title="兑换成功"
		></u-modal>

		<!-- 密码键盘 -->
		<pwd-keyboard v-if="iSPwdKeyboard" title="安全键盘" @success="walletPay" @close="iSPwdKeyboard = false" />

		<!-- 设置密码 -->
		<shopro-auth-modal></shopro-auth-modal>
	</view>
</template>

<script>
import { mapState, mapActions } from 'vuex';
import FormValidate from '@/shopro/validate/form';
import wechat from '@/shopro/wechat/wechat';
import pwdKeyboard from '../../order/components/pwd-keyboard';
export default {
	components: { pwdKeyboard },
	data() {
		return {
			showModal: false,
			iSPwdKeyboard: false,
			money: '', //提现金额
			ruleInfo: '', //提现规则
			// 表单样式
			placeholderStyle: 'font-size: 30rpx; font-weight: 500;color:#C2C7CF;',
		};
	},
	computed: {
		...mapState({
			userinfo: ({ user }) => user.userInfo
		})
	},
	async onLoad() {
		this.getWithdrawRules();
	},
	methods: {
		...mapActions('user',['showAuthModal']),
		checkRegion(obj) {
			this.form.data.province = obj.province.label;
			this.form.data.city = obj.city.label;
		},
		async bindThirdOauth() {
			let that = this;
			wechat.bind();
		},
		// 提现检验
		onWithdrawInput(e) {
			let sVal = String(e.detail.value);
			sVal = sVal.replace(/\b(0+)/gi, '');
			sVal = sVal.replace(/[^\d]/g, '');
			this.money = sVal;
		},
		// 提现
		exchange() {
			const that = this;
			if (this.money <= 0) {
				this.$u.toast('请输入提现金额');
				return;
			}
			
			if (this.money <= 0) {
				this.$u.toast('请输入提现金额');
				return;
			}
			this.$http('user.info').then(res => {
				if (!res.data.pay_pwd || res.data.pay_pwd.length == 0) {
					that.showAuthModal('setPayPwd');
				} else {
					that.iSPwdKeyboard = true;
				}
			});
		},
		// 密码输入完成
		walletPay(paypwd) {
			let that = this;
			that.$http(
				'money.quanyitojindou',
				{
					money: that.money,
					paypwd
				},
				'申请中...',
				false
			).then(res => {
				that.iSPwdKeyboard = false;
				if (res.code === 1) {
					that.money = '';
					that.showModal = true;
					//  #ifdef MP-WEIXIN
					this.$store.dispatch('user/getMessageIds', 'wallet');
					//  #endif
					that.$store.dispatch('user/getUserInfo');
				} else {
					that.$u.toast(res.msg);
				}
			});
		},
		// 提现规则
		getWithdrawRules() {
			let that = this;
			that.$http('money.quanyirule').then(res => {
				if (res.code === 1) {
					that.ruleInfo = res.data;
				}
			});
		},
	}
};
</script>

<style lang="scss">
.head-box {
	background: url($IMG_URL+'/imgs/user/draw_money_head_bg.png') no-repeat;
	background-size: 100% auto;
	min-height: 400rpx;
	padding-bottom: var(--status-bar-height);
	// 可提现
	.wallet-num-box {
		padding: 20rpx 40rpx 0;
		.num-title {
			font-size: 26rpx;
			font-weight: 500;
			color: #ffffff;
			margin-bottom: 20rpx;
		}
		.wallet-num {
			font-size: 60rpx;
			font-weight: 500;
			color: #ffffff;
		}
		.log-btn {
			width: 170rpx;
			height: 60rpx;
			line-height: 60rpx;
			background: rgba(255, 255, 255, 0.1);
			border: 1rpx solid #eeeeee;
			border-radius: 30rpx;
			padding: 0;
			font-size: 26rpx;
			font-weight: 500;
			color: #ffffff;
		}
	}
}
// 提现输入卡片
.draw-card {
	background-color: #fff;
	border-radius: 20rpx;
	width: 690rpx;
	min-height: 530rpx;
	margin: -70rpx auto 0;
	padding: 30rpx;
	.card-title {
		font-size: 30rpx;
		font-weight: 500;
		color: #333333;
		margin-bottom: 30rpx;
	}
	.input-box {
		width: 624rpx;
		border-bottom: 1rpx solid #eee;
		height: 100rpx;
		margin-bottom: 40rpx;
		.unit {
			font-size: 48rpx;
			color: #333;
		}
	}
	.bank-box {
		.name {
			font-size: 28rpx;
			font-weight: 500;
			color: #333333;
		}
		.bank-list {
			.empty-text {
				font-size: 28rpx;
				font-weight: 400;
				color: #999999;
			}

			.sel-box {
				.item-img {
					width: 36rpx;
					height: 36rpx;
				}
				.item-title {
					font-size: 28rpx;
					color: #333333;
				}
			}
		}
	}
	.bank-info {
		height: 50rpx;
		font-size: 28rpx;
		font-weight: 400;
		color: #999999;
		.bank-info-title {
			width: 500rpx;
		}
		.bind-btn {
			padding: 0 20rpx;
			line-height: 50rpx;
			background: #f5f6f8;
			border-radius: 20rpx;
			color: #999;
		}
	}
	.save-btn {
		width: 616rpx;
		height: 86rpx;
		line-height: 86rpx;
		background: linear-gradient(-90deg, #a36fff, #5336ff);
		box-shadow: 0px 7rpx 11rpx 2rpx rgba(124, 103, 214, 0.34);
		border-radius: 43rpx;
		font-size: 30rpx;
		font-weight: 500;
		color: #ffffff;
	}
}
// 提现说明
.draw-notice {
	width: 684rpx;
	height: 327rpx;
	background: #ffffff;
	border-radius: 20rpx;
	padding: 30rpx 35rpx;
	margin: 20rpx auto;
	.title {
		font-size: 30rpx;
		font-weight: 500;
		color: #333333;
		margin-bottom: 30rpx;
	}
	.draw-list {
		font-size: 24rpx;
		font-weight: 400;
		color: #999999;
		margin-bottom: 10rpx;
	}
}
// 提现费方式
.withdraw-modal {
	min-height: 600rpx;
	background-color: #fff;
	.modal-head {
		height: 80rpx;
		font-size: 30rpx;
		font-weight: 600;
		color: #333333;
		border-bottom: 1rpx solid rgba(#dfdfdf, 0.5);
	}
	.modal-content {
		.type-item {
			height: 100rpx;
			border-bottom: 1rpx solid rgba(#dfdfdf, 0.5);
			width: 750rpx;
			.item-img {
				width: 36rpx;
				height: 36rpx;
			}
			.item-title {
				font-size: 28rpx;
				color: #333333;
			}
		}
	}
	.modal-bottom {
		padding: 30rpx;
		.modal-save-btn {
			width: 690rpx;
			height: 80rpx;
			line-height: 80rpx;
			background: linear-gradient(90deg, #a36fff, #5336ff);
			box-shadow: 0 7rpx 11rpx 2rpx rgba(124, 103, 214, 0.34);
			border-radius: 40rpx;
			font-weight: 500;
			color: #ffffff;
		}
	}
}

// 绑定
.form-box {
	.head-title {
		height: 100rpx;
		font-size: 34rpx;
		font-weight: 600;
	}
	.form-save-btn {
		width: 340rpx;
		height: 80rpx;
		line-height: 80rpx;
		background: linear-gradient(90deg, #a36fff, #5336ff);
		box-shadow: 0 7rpx 11rpx 2rpx rgba(124, 103, 214, 0.34);
		border-radius: 40rpx;
		font-weight: 500;
		color: #ffffff;
	}
	.form-cancel-btn {
		width: 340rpx;
		height: 80rpx;
		line-height: 80rpx;
		border: 1rpx solid #999;
		border-radius: 40rpx;
		font-weight: 500;
		color: #999;
	}
}
</style>
